package com.ophiux.cs.domain.consult.model.entity;

import com.ophiux.cs.domain.core.Entity;
import com.ophiux.utils.common.DateUtil;

/**
 * 对话用户登录记录表
 * @author chenh
 *
 */
public class CSUserLoginRecords extends Entity{

	private final static String STATE_ONLINE = "1";
	private final static String STATE_INVALID = "0";
	
	private String TARGET_ID;	//用户ID
	
	private String LOGIN_TOKEN;	//用户登录秘钥  单次登录唯一标志
	
	private String LOGIN_TIME;	//登录时间
	
	private String LOGOUT_TIME;	//退出时间
	
	private String STATE;	//1：在线    0：失效
	
	private String PLATFORM_ID;	//登录平台标识   关联发布平台表“cs_publish_platform”
	
	
	public CSUserLoginRecords(String tARGET_ID, String pLATFORM_ID) {
		super();
		TARGET_ID = tARGET_ID;
		PLATFORM_ID = pLATFORM_ID;
	}

	public CSUserLoginRecords(String tARGET_ID, String lOGIN_TOKEN, String lOGIN_TIME, String lOGOUT_TIME, String sTATE,
			String pLATFORM_ID) {
		super();
		TARGET_ID = tARGET_ID;
		LOGIN_TOKEN = lOGIN_TOKEN;
		LOGIN_TIME = lOGIN_TIME;
		LOGOUT_TIME = lOGOUT_TIME;
		STATE = sTATE;
		PLATFORM_ID = pLATFORM_ID;
	}

	public String getTARGET_ID() {
		return TARGET_ID;
	}

	public void setTARGET_ID(String tARGET_ID) {
		TARGET_ID = tARGET_ID;
	}

	public String getLOGIN_TOKEN() {
		return LOGIN_TOKEN;
	}

	public void setLOGIN_TOKEN(String lOGIN_TOKEN) {
		LOGIN_TOKEN = lOGIN_TOKEN;
	}

	public String getLOGIN_TIME() {
		return LOGIN_TIME;
	}

	public void setLOGIN_TIME(String lOGIN_TIME) {
		LOGIN_TIME = lOGIN_TIME;
	}

	public String getLOGOUT_TIME() {
		return LOGOUT_TIME;
	}

	public void setLOGOUT_TIME(String lOGOUT_TIME) {
		LOGOUT_TIME = lOGOUT_TIME;
	}

	public String getSTATE() {
		return STATE;
	}

	public void setSTATE(String sTATE) {
		STATE = sTATE;
	}

	public String getPLATFORM_ID() {
		return PLATFORM_ID;
	}

	public void setPLATFORM_ID(String pLATFORM_ID) {
		PLATFORM_ID = pLATFORM_ID;
	}
	
	/**
	 * 判断本次登录是否在线
	 * true:在线  	 false:离线
	 * @return
	 */
	public boolean isOnline() {
		return STATE_ONLINE.equals(this.getSTATE()) ? true : false;
	}
	
	/**
	 * 登出
	 * 1.改为失效
	 * 2.记录登出时间
	 */
	public synchronized void logout() {
		//1.改为失效
		this.setSTATE(STATE_INVALID);
		
		//2.记录登出时间
		this.setLOGOUT_TIME(DateUtil.getCurDateStr());
	}
	
	/**
	 * 登录
	 * @param platform  登录平台     预留
	 * 1.改为有效
	 * 2.记录登录时间
	 * 3.生成单次登录唯一token
	 * 4.记录失效时间     -预留   /TODO
	 */
	public synchronized void login() {
		//1.改为有效
		this.setSTATE(STATE_ONLINE);
		
		//2.记录登录时间
		this.setLOGIN_TIME(DateUtil.getCurDateStr());
		
		//3.生成单次登录唯一token
		String login_token = this.createLoginToken();
		this.setLOGIN_TOKEN(login_token);
		
	} 
	
	/**
	 * 生成单次登录唯一token
	 */
	public synchronized String createLoginToken() {
		
		String login_token = "";
		
		//TODO   生成逻辑待实现
		
		return login_token;
		
	}
	
}
